# -*- coding=utf-8 -*-

import requests
import re
import lxml.etree as le

major_url = 'https://youku.cdn-163.com/20180507/6885_4996de9a'
index_url = major_url + '/index.m3u8'
req = requests.get(index_url)
url1 = req.text.split()[-1]
u1 = ''
for char in url1.split('/')[:-1]:
    u1 += '/' + char
print(u1)
url2 = major_url + '/' + req.text.split()[-1]
req2 = requests.get(url2)
# print(req2.text)
file_list = req2.text.split()[5::2]
with open('./video.mp4', 'ab') as f:
    for file in file_list:
        file_url = major_url + u1 + '/' + file
        print(file_url)
        file_req = requests.get(file_url)
        f.write(file_req.content)


req = requests.get('https://www.dytt.com/vod-play-id-11472-src-1-num-1.html').text
content = le.HTML(req).xpath('//div[@class="pageMainTop20"]//script/text()')[0]
pattern = '"url":"(.*?)"'
print(re.findall(pattern, content)[0].replace('\\', ''))
